//
//  Bytes.swift
//  WebSocket
//
//  Created by yaqiang bi on 2017/5/4.
//
//

import Cocoa
import PerfectLib
/// 字节流转换
func BytesTransform()  {
    let i8 = 254 as UInt8
    let i16 = 54045 as UInt16
    let i64 = 17293541094125989887 as UInt64
    let i32 = 4160745471 as UInt32
    let bytes = Bytes()
    
    bytes.import64Bits(from: i64).import32Bits(from: i32).import16Bits(from: i16).import8Bits(from: i8)
    
    let bytes2 = Bytes()
    bytes2.importBytes(from: bytes)
    
    print(i64 == bytes2.export64Bits())
    print(i32 == bytes2.export32Bits())
    print(i16 == bytes2.export16Bits())
    bytes2.position -= MemoryLayout<UInt16>.size
    print(i16 == bytes2.export16Bits())
    print(bytes2.availableExportBytes == 1)
    print(i8 == bytes2.export8Bits())
}
